package com.IO流;

import java.io.*;

public class 复制多级文件夹 {
    public static void main(String[] args) throws IOException {
        File srcFile = new File("D:\\黑马视频\\file");
        File destFile = new File("D:\\黑马视频\\copyfile");
        fileCopy(srcFile, destFile);

    }

    private static void fileCopy(File srcFile, File destFile) throws IOException {
        if (srcFile.isDirectory()) {
            String srcFileName = srcFile.getName();
            File newDestFile = new File(destFile, srcFileName);
            if (!newDestFile.exists()) {
                newDestFile.mkdir();
            }
            File[] files = srcFile.listFiles();
            for (File file : files) {
                fileCopy(file, newDestFile);
            }
        } else {
            File newfile = new File(destFile, srcFile.getName());
            copyFile(srcFile,newfile);
        }
    }

    private static void copyFile(File srcFile, File newfile) throws IOException {
        BufferedReader br=new BufferedReader(new FileReader(srcFile));
        BufferedWriter bw=new BufferedWriter(new FileWriter(newfile));
        String line;
        while((line=br.readLine())!=null){
            bw.write(line);
            bw.newLine();
            bw.flush();
        }
    }
}
